
interface childrenConf {
    path: string,
    method: string,
    handler: any,
}
interface routersConf {
    prefix: string,
    children: Array<childrenConf>
}
/**
 * 定义注册的路由数组
 */
export const Routers: Array<routersConf> = [];
let children: Array<childrenConf> = [];

export function controller(url: string) {
    return function (target: any) {
        Routers.push({
            prefix: url,
            children
        })
        children = []
    }
}

function createRouterMapping(method: string) {
    return (url: string) => {
        return (target: any, name: string) => {
            children.push({
                path: url,
                method: method,
                handler: target[name],
            })
        }
    }
}

export const post = createRouterMapping("post");
export const get = createRouterMapping("get");
